package dxn.nl.file.client.model.dto;

import dxn.nl.file.client.model.enums.ExportQueryDataTypeEnum;
import lombok.Data;

import java.util.*;

@Data
public class CsExportDealTypeHeadDto  {
    public static final String defaultSheetName = "sheet1";
    /**
     * 列头名
     */
    private ExportQueryDataTypeEnum exportType = ExportQueryDataTypeEnum.page;
    private HashMap<String,CsExportExcelSheetHeadDto> sheetHeadMap = new HashMap<>();

    /**
     * 字段名
     */
    public CsExportExcelSheetHeadDto getDefaultSheetHeads()
    {
        return sheetHeadMap.get(defaultSheetName);
    }

    public void setDefaultSheetHeads(List<CsExportExcelHeadDto> heads)
    {
        CsExportExcelSheetHeadDto sheetHeadDto = new CsExportExcelSheetHeadDto();
        sheetHeadDto.setHeadDtoList(heads);
        sheetHeadDto.setHasTitle(true);
        sheetHeadMap.put(defaultSheetName,sheetHeadDto);
    }

    public void setDefaultSheetHeads(CsExportExcelSheetHeadDto sheetHeadDto)
    {
        sheetHeadMap.put(defaultSheetName,sheetHeadDto);
    }

    public void setSheetHeads(CsExportExcelSheetHeadDto sheetHeadDto,String sheetName)
    {
        sheetHeadMap.put(sheetName,sheetHeadDto);
    }

    public CsExportExcelSheetHeadDto getSheetHeads(String sheetName)
    {
        return sheetHeadMap.get(sheetName);
    }

    public void sortHead()
    {
        for(Map.Entry<String,CsExportExcelSheetHeadDto> entry : sheetHeadMap.entrySet())
        {
            entry.getValue().sortHead();
        }
    }

    public static CsExportDealTypeHeadDto streamDeal(List<CsExportExcelHeadDto> heads)
    {
        CsExportDealTypeHeadDto dto = new CsExportDealTypeHeadDto();
        dto.setExportType(ExportQueryDataTypeEnum.stream);
        CsExportExcelSheetHeadDto sheetHeadDto = new CsExportExcelSheetHeadDto();
        sheetHeadDto.setHeadDtoList(heads);
        sheetHeadDto.setHasTitle(true);
        dto.setDefaultSheetHeads(sheetHeadDto);
        return dto;
    }

    public static CsExportDealTypeHeadDto pageDeal(List<CsExportExcelHeadDto> heads)
    {
        CsExportDealTypeHeadDto dto = new CsExportDealTypeHeadDto();
        dto.setExportType(ExportQueryDataTypeEnum.page);

        CsExportExcelSheetHeadDto sheetHeadDto = new CsExportExcelSheetHeadDto();
        sheetHeadDto.setHeadDtoList(heads);
        sheetHeadDto.setHasTitle(true);
        dto.setDefaultSheetHeads(sheetHeadDto);
        return dto;
    }

    public static CsExportDealTypeHeadDto pageNoTitle()
    {
        CsExportDealTypeHeadDto dto = new CsExportDealTypeHeadDto();
        dto.setExportType(ExportQueryDataTypeEnum.page);

        CsExportExcelSheetHeadDto sheetHeadDto = new CsExportExcelSheetHeadDto();
        sheetHeadDto.setHeadDtoList(new ArrayList<>());
        sheetHeadDto.setHasTitle(true);
        dto.setDefaultSheetHeads(sheetHeadDto);
        return dto;
    }

    public static CsExportDealTypeHeadDto pageNoTitle(List<String> sheets)
    {
        CsExportDealTypeHeadDto dto = new CsExportDealTypeHeadDto();
        dto.setExportType(ExportQueryDataTypeEnum.page);

        CsExportExcelSheetHeadDto sheetHeadDto = new CsExportExcelSheetHeadDto();
        sheetHeadDto.setHeadDtoList(new ArrayList<>());
        sheetHeadDto.setHasTitle(true);
        dto.setDefaultSheetHeads(sheetHeadDto);
        return dto;
    }
}
